const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return `${[year, month, day].map(formatNumber).join('/')} ${[hour, minute, second].map(formatNumber).join(':')}`
}

const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : `0${n}`
}

var app = getApp();
var host = 'http://api_devs.wanxikeji.cn/';

/** 
 * POST请求，
 * URL：接口
 * postData：参数，json类型 {'id':11}
 * doSuccess：成功的回调函数
 * doFail：失败的回调函数
 **/
function request(url, postData, doSuccess, doFail) {
     wx.request({
       //项目的真正接口，通过字符串拼接方式实现
       url: host + url,
       header: {
         "content-type": "application/json;charset=UTF-8"
       },
       data: postData,
       method: 'POST',
       success: function (res) {
         //参数值为res.data,直接将返回的数据传入
         doSuccess(res.data);
       },
       fail: function () {
         doFail();
       },
     })
   }


  //  module.exports.request = request;


module.exports = {
  formatTime,
  request
}
